package com.tevintao.marketingsystem.provider;


import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

import com.tevintao.marketingsystem.task.ReportMessage;

public class ChatMessageBean {

    private int id;
    private String account;
    private String talker;
    private String nickName;
    private String content;
    private String filePath;
    private int type;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getTalker() {
        return talker;
    }

    public void setTalker(String talker) {
        this.talker = talker;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public static ChatMessageBean getNewChat(Context context) {
        Uri uri = Uri.parse("content://chat_new_message");
        Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
        ChatMessageBean bean = null;
        if (cursor != null && cursor.moveToNext()) {
            bean = new ChatMessageBean();
            bean.setId(cursor.getInt(cursor.getColumnIndex("id")));
            bean.setType(cursor.getInt(cursor.getColumnIndex(ReportMessage.KEY_PARAMS_TYPE)));

            bean.setAccount(cursor.getString(cursor.getColumnIndex(ReportMessage.KEY_PARAMS_ACCOUNT)));
            bean.setTalker(cursor.getString(cursor.getColumnIndex(ReportMessage.KEY_PARAMS_TALKER)));
            bean.setNickName(cursor.getString(cursor.getColumnIndex(ReportMessage.KEY_PARAMS_NIKE_NAME)));
            bean.setContent(cursor.getString(cursor.getColumnIndex(ReportMessage.KEY_PARAMS_CONTENT)));
            bean.setFilePath(cursor.getString(cursor.getColumnIndex(ReportMessage.KEY_FROM_FILE_PATH)));
        }
        if (null != cursor) {
            cursor.close();
        }
        return bean;
    }

    public static boolean deleteChatMessage(Context context, int id) {
        Uri uri = Uri.parse("content://chat_new_message");
        return context.getContentResolver().delete(uri, "id=?", new String[]{"" + id}) > 0;
    }

    @Override
    public String toString() {
        return "id = "+ id + " account = " + account + " talker = " + talker + " nickName = " + nickName + " content = " + content + " filePath = " + filePath + " type = " + type;
    }
}
